var platform = 'pad' //设备类型
var appId = '54'//应用ID
var url = "http://10.0.22.78:7003"
//var url = "http://10.0.17.111:8080"
var currentCode = '8611018517';
var currentPwd = '111111'
var alertPopup = null;
//查询当前登录人及直属下属列表
function loadAgent($scope){
	var json={"url":url+"/edebit_agentController.do","parameters":{"method":"queryUnderAgent","agentCode":currentCode}};  
    httpRequestByPost(json,function(obj){
        var returnJson=eval("("+obj+")");
        $scope.$apply(function (){
            $scope.agentList =returnJson.agentList;
        });
        alertPopup.close(); 
    },function (){
        alert("查询出错误");
    });  
}
//根据当前选中的业务员查询保单信息
function loadPolicyByAgent(code,pay_date,$scope){
	var json={"url":url+"/edebit_renewalfee.do","parameters":{"method":"queryAppnts","agent_code":code,"pay_date":pay_date}};  
    httpRequestByPost(json,function(obj){
        var returnJson=eval("("+obj+")");
        $scope.$apply(function (){
            $scope.appLists = returnJson.appnetsPolicysListVo.appntsPolicysListVo.appntsList;
        });
        alertPopup.close(); 
    },function (){
        alert("查询出错误");
    });
}
//收费接口
function applyPolicy(item,$scope,$timeout,$ionicPopup){ 
    var json={"url":url+"/edebit_renewalfee.do","parameters":{"method":"saveRenewalMoney","contNo":item.contNo,"pay_date":item.payToDate}};  
    httpRequestByPost(json,function(obj){
        var returnJson=eval("("+obj+")");
        if('0000' == item.payState){
            alertPopup.close();//正在加载的弹出层
        }
        var flag = returnJson.renewalPayVo.flag;
        if('MS01' == flag){
            alertPopupFun($ionicPopup,'charging',returnJson.renewalPayVo.failedreason);
            $timeout(function (){
                alertPopup.close();
            },3000);
           $scope.modal.hide(); 
        }else if('MS02' == flag){
            alertPopupFun($ionicPopup,'loser',"收费失败（"+returnJson.renewalPayVo.failedreason+")");
            $timeout(function (){
                alertPopup.close();
            },3000);
        }
        else if('MS03' == flag){
            alertPopupFun($ionicPopup,'loser',returnJson.renewalPayVo.failedreason);
            $timeout(function (){
                alertPopup.close();
            },3000);
        }
        else if('MS04' == flag){
            alertPopupFun($ionicPopup,'loser',"收费失败（"+returnJson.renewalPayVo.failedreason+")");
            $timeout(function (){
                alertPopup.close();
            },3000);
        }else if('1111' == flag||'0000' == flag){
            alertPopupFun($ionicPopup,'charging',returnJson.renewalPayVo.failedreason);
            $timeout(function (){
                alertPopup.close();
            },3000);
        }
    },function (){
        alertPopupFun($ionicPopup,'loser','查询出错误');
        $timeout(function (){
            alertPopup.close();
        },3000);
    });
}

/**********alert提醒***********/
function alertPopupFun($ionicPopup,icon,word){
	alertPopup = $ionicPopup.alert({
		template: '<div class="pop_up_box"><span class="'+icon+'"></span>'+word+'</div>'
	});
}